<template>
  <div>
    <el-dialog
      v-model="Visible"
      width="40%"
      :title="title"
      :close-on-click-modal="false"
      @close="handleclose"
    >
      <el-form label-width="100px">
        <el-form-item :label="title1">
          <el-input v-model="Refused.reason" type="textarea"></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="Visible = false">取 消</el-button>
          <el-button type="primary" @click="handleSaveEdit">确定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script>
import { ref, reactive } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import api from "../api/api";
export default {
  setup(props, context) {
    const Visible = ref(context.attrs.Visible);
    const title = ref(context.attrs.title);
    const title1 = ref(context.attrs.title1);
    const applyId = ref(context.attrs.applyid);
    const carbonDTO = ref(context.attrs.carbonDTO);
    const flowStepId = ref(context.attrs.flowStepId);
    console.log(carbonDTO.value);
    const createUnit = ref(context.attrs.createUnit);
    const Refused = reactive({
      id: applyId.value,
      flowStepId: flowStepId.value,
      reason: "",
      createUnit: createUnit,
      fileListType: 0,
    });
    const handleclose = () => {
      Visible.value = false;
      context.emit("handleclose", Visible.value);
    };
    const handleSaveEdit = () => {
      if (!Refused.reason) {
        ElMessage.error("请输入拒绝原因");
        return;
      }
      api
        .postFormAPI("carbon/system/carbon/refuse", Refused)
        .then((res) => {
          if (res.data.code == 1) {
            Visible.value = false;
            context.emit("handleSaveEdit", Visible.value);
            ElMessage.success("提交成功");
          } else {
            ElMessage.error(res.data.message);
          }
          //数据处理
        })
        .catch((err) => {
          console.log(err);
        });
      context.emit("handleSaveEdit", Refused);
    };
    return {
      title,
      title1,
      Visible,
      Refused,
      handleclose,
      handleSaveEdit,
    };
  },
};
</script>
